home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / ins_msb / 9203 / parspath.bas < prev    next >
BASIC Source File  |  1992-02-06  |  3KB  |  73 lines

  1. ' ParsPath.Bas - Support module to contain the ParsePathname subprogram.
  2.  
  3. ' $INCLUDE: 'QUALNAME.BI'
  4. ' $INCLUDE: 'PARSPATH.BI'
  5. ' $INCLUDE: 'QB.BI'
  6.  
  7. ' Note: This module requires the support module QUALNAME.BAS
  8. '       for its operation.
  9.  
  10. SUB ParsePathname (InSpec$, Drive$, Path$, Entry$)
  11. ' ParsePathname - Split the file specification in InSpec$
  12. '                 into its component parts (after trying
  13. '                 to qualify it).
  14. IF LEN(InSpec$) > 0 THEN
  15.   OldSpec$ = InSpec$        ' make a copy for possible later use
  16.   OldDrive$ = ""
  17.   InSpec$ = QualifyName$(InSpec$) ' qualify the name (DOS 3.X > only)
  18.   ' Let's see if the network redirector messed with the name
  19.   IF LEFT$(InSpec$, 2) = "\\" THEN
  20.     ' Yup. This filename is on a network. We'll need to remove
  21.     ' the \\SERVER_NAME\VOLUME_NAME prefix, then stick a drive
  22.     ' letter back on the front of the name.
  23.     InSpec$ = MID$(InSpec$, INSTR(MID$(InSpec$, 3), "\")+2)
  24.     InSpec$ = MID$(InSpec$, INSTR(MID$(InSpec$, 2), "\")+1)
  25.     IF MID$(OldSpec$, 2, 1) = ":" THEN ' Did user specify a drive letter?
  26.       OldDrive$ = LEFT$(OldSpec$, 2)   ' yes, use the drive they specified
  27.     ELSE                ' nope, use current drive
  28.       ' won't be right if file found in APPEND path
  29.       OldDrive$ = LEFT$(CURDIR$, 2)
  30.     END IF
  31.   END IF
  32.   ' More initializations for the name parsing routine
  33.   Entry$ = "": InLen% = LEN(InSpec$): ParseState% = 0: CHPos% = InLen%
  34.   DO WHILE CHPos%
  35.     SELECT CASE ParseState%
  36.       CASE 0
  37.           ' Whatever was entered after the last "\" is an entry name
  38.           IF INSTR(":\", MID$(InSpec$, CHPos%, 1)) = 0 THEN
  39.             Entry$ = MID$(InSpec$, CHPos%, 1) + Entry$
  40.             CHPos% = CHPos% - 1
  41.           ELSE
  42.             ' We don't want to include the "\" in the next component
  43.             ' we're going to parse, UNLESS the next component is
  44.             ' going to be the root directory specification. 
  45.             IF MID$(InSpec$, CHPos%, 1) = "\" THEN
  46.               IF CHPos% > 1 THEN
  47.                 IF MID$(InSpec$, CHPos% - 1, 1) <> ":" THEN
  48.                   CHPos% = CHPos% - 1
  49.                 END IF
  50.               END IF
  51.             END IF
  52.             ParseState% = ParseState% + 1           ' next state
  53.           END IF
  54.       CASE 1
  55.           ' Here, we build the path that leads the to entry name.
  56.           IF INSTR(":", MID$(InSpec$, CHPos%, 1)) = 0 THEN
  57.             Path$ = MID$(InSpec$, CHPos%, 1) + Path$
  58.             CHPos% = CHPos% - 1
  59.           ELSE
  60.             ParseState% = ParseState% + 1
  61.           END IF
  62.       CASE 2
  63.           ' Here, we build the drive specfication also
  64.           ' (also, because the drive spec is part of the drive spec).
  65.           Drive$ = MID$(InSpec$, CHPos%, 1) + Drive$
  66.           Path$ = MID$(InSpec$, CHPos%, 1) + Path$
  67.           CHPos% = CHPos% - 1
  68.     END SELECT
  69.   LOOP
  70.   IF LEN(Drive$) = 0 THEN Drive$ = OldDrive$
  71. END IF
  72. END SUB
  73.